package com.fancy.mobileschool.task;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import okhttp3.Call;


/**
 * Created by Jackie on 2017/10/23.
 */

public class TaskExecutor {

    private static ExecutorService es = Executors.newFixedThreadPool(2);

    public static <T> T getResult(Callable<T> callable) {
        Future<T> future = es.submit(callable);
        try {
            return future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static void execute(Runnable runnable) {
        es.execute(runnable);
    }
}
